package lectura_escritura;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class LeerEscribirMujerPerfecta {
	
	private String entrada;
	private List<String> listaCapitulos;
	
	public LeerEscribirMujerPerfecta(){
		listaCapitulos = new ArrayList<String>();
	}
	
	public List<String> getListaCapitulos(){
		return listaCapitulos;
	}
	
	public List<String> lectura(){
		
		try {
			InputStream lector = new FileInputStream("/home/javictoria/Escritorio/parseo_EN.txt");
			BufferedReader bf = new BufferedReader(new InputStreamReader(lector));
			
			
			while((entrada=bf.readLine())!=null){
				
				listaCapitulos.add(entrada);
				
			}
			
			lector.close();
			bf.close();
				
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch(IOException e){
	    	e.printStackTrace();
	    }
		
		return listaCapitulos;
       	
	}
	
	
	public void escritura(List<String> capitulos){
		
		try {
			FileWriter f = new FileWriter("/home/javictoria/Escritorio/contents_mujer_EN.js");
			f.write("var trabContents = {\n");
			f.write("\t\"trabContents\":{\n");
			f.write("\t\t\"EN\":[\n");
			for(String cap: capitulos){
				
				f.write("\t\t\t\"<p>"+cap+"</p>\",\n");
			}
			f.write("\t\t]\n\t}\n};");
			f.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
}
